home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
DIEXTRAC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-16
|
3KB
|
119 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: diextrac.c
// Title: Data File I/O Library
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains to extract data from a data file to an external file.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <di.h>
//----------------------------------------------------------------------------
// Description: Extract data to an external file.
// Parameters: hlf Logical file handle.
// pcszFile File name to extract to
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioExtract(HLF hlf, PCSZ pcszFile)
{
FPOS fsize;
FLAG16 fs = FL_CREATE|FL_TRUNCATE|FL_READWRITE|FL_DENYREADWRITE|FL_BINARY;
HF hf;
if (!DioGetSize(hlf, &fsize) || !DioSeek(hlf, 0))
return FALSE;
// Open external file
if (!FileOpen(&hf, pcszFile, fs, NULL))
return FALSE;
// Copy data
if (!FileCopy(hf, 0, di.logical[hlf].hf, di.logical[hlf].fbase, fsize))
{
FileClose(hf);
return FALSE;
}
FileClose(hf);
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Extract data to an external file.
// Parameters: pcsz Physical file name
// pcszLogical Logical file name
// usType File type
// pcszFile File name to extract to
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioExtractFile(PCSZ pcsz, PCSZ pcszLogical, USHORT usType, PCSZ pcszFile)
{
HPF hpf;
HLF hlf;
BOOL fUser;
BOOL fResult = FALSE;
Assert(pcszLogical);
if (HIUSHORT(pcsz))
{
if (!DioOpenPhysical(pcsz, &hpf, FALSE))
return FALSE;
fUser = FALSE;
}
else
{
hpf = LOUSHORT(pcsz);
Assert(hpf >= 0 && hpf < MAX_PHYSICAL_FILES);
Assert(di.physical[hpf].fUsed);
fUser = TRUE;
}
if (!DioOpenLogical(pcszLogical, &hlf, usType))
goto ERROR_EXIT;
if (!DioExtract(hlf, pcszFile))
goto ERROR_EXIT;
fResult = TRUE;
ERROR_EXIT:
if (!fUser)
DioClosePhysical(hpf);
return fResult;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------